<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1.0, user-scalable=no">
	

	<title>我要爆料</title>
	<link rel="stylesheet" href="{$_C.hy_path}css/card/main.css">
</head>
<body class="bl-bg">
	<form>
	<div class="wrapper bl-wrapper">
		<p class="bl-title mart-35 marb-30">
			<img class="bl-title3 moveFromLeft delay1000" src="{$_C.hy_path}images/card/title2.png" alt="">
			<img class="bl-title1 moveFromRight delay500" src="{$_C.hy_path}images/card/title.png" alt="">
			<img class="bl-title2 moveFromRight delay1500" src="{$_C.hy_path}images/card/title1.png" alt="">
		</p>
		<p class="font-12 marb-14"><input id="bl-name" name="name" class="bl-input" type="text" placeholder="姓名："></p>
		<p class="font-12 marb-14"><input id="bl-pnum" name="phone" class="bl-input" type="text" placeholder="联系电话："></p>
		<div class="bl-text marb-14">
			<textarea id="bl-info" class="bl-text-inner" name="content" placeholder="爆料内容："></textarea>
			<span class="tips cl-f-lgray">仅限 1000 字</span>
		</div>
		<div class="upload-list">
			<div class="upload upload-empty"><span class="upload-tips">上传照片</span></div>
		</div>
		<p class="btn-con"><a data-type="yes" class="yf-post btn font-14 cl-btn-blue marb-14">提 交</a></p>
	</div>
	</form>	
		<script>
		var _hmt = _hmt || [];
		(function() {
		  var hm = document.createElement("script");
		  hm.src = "//hm.baidu.com/hm.js?808c919bdc18475fae43350429e11cb4";
		  var s = document.getElementsByTagName("script")[0]; 
		  s.parentNode.insertBefore(hm, s);
		})();
		</script>
		<script type="text/javascript" src="{$_C.hy_path}js/jquery-1.10.2.min.js"></script>
		<script type="text/javascript" src="{$_C.hy_path}js/main.js"></script>
		<script src="{$_C.hy_path}js/yf.js"></script>
		<script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
		<script>
			
		
		var img_url = "{$_C.hy_path}images";			
		
		var add_img = $(".upload-empty");
		
		
		var num = 0;

		var limit_num = 9;
		
		//不打断alert
		function warn(msg,opt,left,top){
			if(opt){
			 	var obj = $("#"+opt);
			}
		 	new Toast({ context:$('body'),message:msg},obj,left,top).show();
		}
		var Toast = function(config,obj,left,top){
			this.context = config.context==null?$('body'):config.context;//上下文
			this.message = config.message;//显示内容
			this.time = config.time==null?5000:config.time;//持续时间
			this.left = config.left;//距容器左边的距离
			this.top = ($(document).height()/4)*2;//距容器上方的距离
			if(obj){ 
			this.left = obj.offset().left + left;
			this.top = obj.offset().top + top;
			}
			this.init();
		}
		var msgEntity;
		Toast.prototype = {
			//初始化显示的位置内容等
			init : function(){
				$("#toastMessage").remove();
				//设置消息体
				var msgDIV = new Array();
				msgDIV.push('<div id="toastMessage">');
				msgDIV.push('<span>'+this.message+'</span>');
				msgDIV.push('</div>');
				msgEntity = $(msgDIV.join('')).appendTo(this.context);
				//设置消息样式
				var left = this.left == null ? this.context.width()/2-17-msgEntity.find('span').width()/2 : this.left;
				var top = this.top == null ? '20px' : this.top;
				msgEntity.css({ position:'absolute',top:top,'z-index':'9999',left:left,'background-color':'#2a70e6',color:'white','font-size':'14px',padding:'12px',margin:'5px','border-radius':'4px','-moz-border-radius':'4px','-webkit-border-radius':'4px','font-family':'微软雅黑'});
				//msgEntity.addClass(".toast");
				msgEntity.hide();
		 	},
			//显示动画
			show :function(){
				msgEntity.fadeIn(this.time/2);
				msgEntity.fadeOut(this.time/2);
			}
		}

			$(function(){
				
				/* $('.upload-empty').click(function(){
					$(this).before(function(){
						return '<div class="upload upload-img" style="background-image:url('+img_url+'/card/photo-img.png)"></div>';
					});
				}) */
				
				$('.yf-post').click(function(){
					
					var _this = $(this);
					var type = _this.attr('data-type');
					if(type == 'done')
					{
						warn("你今天已报过料了");
					}
					else if(type == 'yes')
					{
						var data = {};
						var data_arr = $('form').serialize().replace(/\+/g,' ').split('&');
						for(var i=0;i<data_arr.length;i++)
						{
							var temp=data_arr[i].split('=');
							if(typeof(data[hungry.util.utf8_decode(temp[0])])!='undefined')
							{
								var arr=[];
								if(data[hungry.util.utf8_decode(temp[0])] instanceof Array)
								{
									arr=data[hungry.util.utf8_decode(temp[0])];
								}
								else
								{
									arr.push(data[hungry.util.utf8_decode(temp[0])]);
								}
									arr.push(hungry.util.utf8_decode(temp[1]));
									data[hungry.util.utf8_decode(temp[0])]=arr;
							}
							else
							{
								data[hungry.util.utf8_decode(temp[0])]=hungry.util.utf8_decode(temp[1]);
							}
						}
						/*  _this.attr('data-type', 'no'); 
						_this.text('提交中'); */
							
							/*  alert(JSON.stringify(data)); */ 
						$.post('index.php?g=mobile&m=suipai&a=uploadData',data,function(result){
							
							if(result.error == 0)
							{
								warn(result.content);
								_this.attr('data-type', 'done');
								_this.attr('data-type', 'yes');
								setTimeout("location.reload()",3000);
								//location.reload();
							}
							else
							{
								
								warn(result.content);
								_this.attr('data-type', 'yes');
								_this.text('提交');
							}
						},'json');
					}
					else
					{
						warn("数据提交中");
					}
				});
			});
			
			wx.config({
				debug: false,
				appId: '{$jsdk.appId}',
				timestamp: {$jsdk.timestamp},
				nonceStr: '{$jsdk.nonceStr}',
				signature: '{$jsdk.signature}',
				jsApiList: [
					'chooseImage',
					'previewImage',
					'uploadImage',
					'downloadImage',
					 'onMenuShareTimeline',
		      'onMenuShareAppMessage'
				]
			});
			
			var images = {
				    localId: [],
				    serverId: []
				  };
			
		
				  
			wx.ready(function(){
				
				
				
				
				 wx.onMenuShareTimeline({
    
    title: '报料有奖',
   // desc: '一经采纳，即有大奖！',
  imgUrl: 'http://g4.airefp.com/ws/Uploads/share/baoliao_share.png',
  
      trigger: function (res) {
       
      },
      success: function (res) {
       			
			
      },
      cancel: function (res) {
       
      },
      fail: function (res) {
        alert(JSON.stringify(res));
      }
    });
    
	wx.onMenuShareAppMessage({
   // link:'http://wxyx.weidianit.com/index.php?g=home&m=shake&a=index&pid='+pid,
     title: '报料有奖',
    desc: '一经采纳，即有大奖！',
  imgUrl: 'http://g4.airefp.com/ws/Uploads/share/baoliao_share.png',
    success: function () { 
	
				
    },
    cancel: function () { 
        // 用户取消分享后执行的回调函数
    }
});
				
				
	
	
	
	add_img.click(function(){
		/* 
		var img = "images/set_img1.png";
		add_img(img);
		return;
		 */
		if(num>=limit_num)
		{
			showAlert("至多可上传9张图片");
			return;
		}
		 
		wx.chooseImage({
			success: function (res) {
				
		        images.localId = res.localIds;
		        
		        if (images.localId.length == 0) {
		  	      	showAlert('请先选择图片');
					return;
		  	    }
		        
		        var i = 0; 
		        var length = images.localId.length;
		        images.serverId = [];
		        
		        function upload() 
		        {
					
					if(num>=limit_num-1)
					{
						add_img.fadeOut("fast");
							
					}
					
					var img;
					
		        	wx.uploadImage({
		        		localId: images.localId[i],
		      		    success: function (res) {
		      		    	i++;
		      		    	num++;
		      		    	images.serverId.push(res.serverId);
		      		    	img = res.serverId;
		      		    	
		      		    	//alert(images.localId[i-1]);
		      		    	
		      		    	add_img_div(images.localId[i-1],img);
		      		    	 
		      		    	
		      		    	
		      		    	if(num>=limit_num)
							{
								return;
									
							}
		      		    	
		      		    	
		      		    	if(i<length)
		      		    	{
		      		    		upload();
		      		    	}
		      		    	
		      		    	
		      		    }
		        	});
		        }
		        
		        upload();
		    }
		});
	});
	
	
	
	

	function add_img_div(limg,simg)
	{
		
		add_img.before(function(){
			return '<input type="hidden" name="media" value="'+simg+'" /><div class="upload upload-img" style="background-image:url('+limg+')"></div>';
		});
	
		
		/* var img_div = "<div class='debug_img' style='background-image:url("+limg+");background-repeat:no-repeat;background-size:100%;background-position:50%'>"
			+"<img src='"+img_url+"/0.png'  width='100%' />"
			+"<div class='cut' onclick='cut_img(this)'>"
			+"<img class='debug_cut'  src='"+img_url+"/cut2.png'  width='100%' />"
			+"<input type='hidden' name='media' value='"+simg+"' />"
			+"</div>"
			+"</div>";
			
			
			
	    	$(img_div).insertBefore("#add_img"); */
	    	
	}


			});
			
			
			function cut_img(obj)
			{
				alert(num);
				num--;
				$(obj).parent().fadeOut("fast").remove();
				if(num==limit_num-1)
				{
					$("#add_img").fadeIn("slow");
					
				}
			}	
			
		</script>
	</body>
</html>
